//
//  AppDelegate.swift
//  todoApp
//
//  Created by lili on 15/2/4.
//  Copyright (c) 2015年 ll studio. All rights reserved.
//

import UIKit
import MMDrawerController

@UIApplicationMain

class AppDelegate: UIResponder, UIApplicationDelegate, WXApiDelegate {

    var window: UIWindow?
    
    var wechatHandleDelegate: WXApiDelegate?
    
    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        
         let backGroundimage=UIImage(named:"banner2.png")
        
        var dic:NSDictionary = NSDictionary(object: UIColor.whiteColor(), forKey: NSForegroundColorAttributeName)
//        UIBarButtonItem.appearance().setTitleTextAttributes(dic as [NSObject : AnyObject], forState: UIControlState.Normal)
        
        
        
    //UINavigationBar.appearance().setBackgroundImage(backGroundimage, ui)
        UINavigationBar.appearance().tintColor = UIColor.whiteColor()
        UINavigationBar.appearance().titleTextAttributes = dic as! [String : AnyObject]
       UINavigationBar.appearance().setBackgroundImage(backGroundimage, forBarMetrics: UIBarMetrics.Default)
        
        
        
        // Override point for customization after application launch.
        
        //初始化短信服务应用
        //SMS_SDK.registerApp("71736eba1c5c", withSecret: "f3b4a9886266d2b069693bde8f2d104d")
        SMS_SDK.registerApp("725db6e01970", withSecret: "d23ee78ab5ea864dcc44710df911f82b")

        //注册AVOSCloud 服务
        AVOSCloud.setApplicationId("95cyarg8rdlexjeainc027t45ph35b5iq3jph84dvyzzqn4t", clientKey: "pw58rpimq2d75lurd4d8f72k4jva69as49vydl2ifbj8o0wh");
        
        ShareSDK.registerApp("710b91045820")
        
        
        ShareSDK.connectWeChatWithAppId("wx0215b66155866583", appSecret: " cd6e4c111a79ed793a417334d76bf28d",wechatCls: WXApi.classForCoder())
        
        ShareSDK.connectQZoneWithAppKey("1104362614", appSecret: "Dl3xD8tyAHJQ8RfY", qqApiInterfaceCls: QQApiInterface.classForCoder(), tencentOAuthCls: TencentOAuth.classForCoder())
        
//        ShareSDK.connectSinaWeiboWithAppKey("568898243", appSecret: "38a4f8204cc784f81f9f0daaf31e02e3", redirectUri: "http://www.sharesdk.cn", weiboSDKCls: WeiboSDK.classForCoder())
        
        var storyBoard = UIStoryboard(name: "Main", bundle: nil)
        
        var mainVC:UINavigationController = storyBoard.instantiateViewControllerWithIdentifier("MasterTableViewControllerNav") as! UINavigationController;
        var loginVC: UIViewController! = storyBoard.instantiateViewControllerWithIdentifier("LoginViewController") as! UIViewController
    
        var logNav : UINavigationController = UINavigationController(rootViewController: loginVC)
        
        var rootVC = MMDrawerController(centerViewController: mainVC, leftDrawerViewController: logNav)
        
        
        //设置弹出菜单宽度
        var myRect:CGRect = UIScreen.mainScreen().bounds;
        var screenwidth:CGFloat = myRect.size.width

        rootVC.setMaximumLeftDrawerWidth(0.8*screenwidth, animated: true, completion: nil)
        
        
        rootVC.openDrawerGestureModeMask = MMOpenDrawerGestureMode.PanningCenterView
        rootVC.closeDrawerGestureModeMask = [MMCloseDrawerGestureMode.TapCenterView , MMCloseDrawerGestureMode.PanningCenterView]
        rootVC.shouldStretchDrawer = false
        rootVC.showsShadow =  true
        
        
        
        self.window?.rootViewController = rootVC
        self.window?.makeKeyAndVisible()
        
        //regist wechat sdk
//        WXApi.registerApp("1104362614")
//        WXApi.registerApp("wxd930ea5d5a258f4f")
        
        //regist weibo sdk
//        WeiboSDK.registerApp("1403638662")
        return true
    }

    func applicationWillResignActive(application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

    func applicationWillEnterForeground(application: UIApplication) {
        // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
    }

    func applicationDidBecomeActive(application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    func applicationWillTerminate(application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }

     func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
        
       /* var urlScheme : String! = url.scheme
        
        if urlScheme!.hasPrefix("wb")
        {
            //微博
            if let del = self.wbHandleDelegate
            {
                return WeiboSDK.handleOpenURL(url, delegate: del)
            }
            else
            {
                return WeiboSDK.handleOpenURL(url, delegate: self)
                
            }
        }
        else
        {
            //微信
            if let del = self.wechatHandleDelegate
            {
                return WXApi.handleOpenURL(url, delegate: del)
            }
            else
            {
                return WXApi.handleOpenURL(url, delegate: self)
                
            }
        }
  */
        
        //使用sharesdk代码
        return ShareSDK.handleOpenURL(url, sourceApplication: sourceApplication, annotation: annotation, wxDelegate: self)

    }
    
    func  applicaiton(application: UIApplication,handleOpenURL url: NSURL) ->Bool {
        
        return ShareSDK.handleOpenURL(url, wxDelegate: self)
        
    }
    
    func onResp(resp: BaseResp!) {
        
    }
}

